package com.rd.student.jike.class2.xuezhixin.day0808;

import com.rd.student.jiaji.class4.suyan.zrrd.day08.C;

import java.io.File;
import java.io.FileWriter;
import java.io.Reader;
import java.io.Writer;
import java.util.LinkedList;
import java.util.Scanner;

public class Work01 {
    public static void main(String[] args) throws Exception{
        Scanner scanner = new Scanner(System.in);
        System.out.println("您想录入的学生数：");
        int num = scanner.nextInt();
        int i = 0;
        LinkedList<String> list = new LinkedList<>();
        String s = "姓名" + "\t" + "语文成绩" + "\t" + "数学成绩" + "\t" + "总分" + "\n" ;
        list.add(s);
        while (i<num){
            System.out.println("学生姓名：");
            String name = scanner.next();
            System.out.println("学生语文成绩：");
            int ChineseGrade = scanner.nextInt();
            System.out.println("学生数学成绩：");
            int MathGrade = scanner.nextInt();
            Student student = new Student(name,ChineseGrade,MathGrade);
            int AllGrade = student.allGrade();
            String str = name + "\t" + ChineseGrade + "\t" + MathGrade + "\t" + AllGrade + "\n" ;
            list.add(str);
            System.out.println("第" + (++i) + "个学生" + name + "录入成功");
        }

        File file = new File("Student.txt");
        Writer writer = new FileWriter(file);
        for (String str : list){
            writer.write(str);
        }
        System.out.println("数据保存完毕，请到Student.txt文件中查看");
        writer.close();
    }
}

class Student{
    private String name;
    private int ChineseGrade;
    private int MathGrade;

    public Student(String name, int chineseGrade, int mathGrade) {
        this.name = name;
        ChineseGrade = chineseGrade;
        MathGrade = mathGrade;
    }

    public int allGrade(){
        return ChineseGrade + MathGrade;
    }
}
